package com.imageflowpro.image_flow_pro.controller.admin;

import com.imageflowpro.image_flow_pro.dto.AdminGetOrderListDTO;
import com.imageflowpro.image_flow_pro.po.OrderComment;
import com.imageflowpro.image_flow_pro.result.Result;
import com.imageflowpro.image_flow_pro.service.IMediaOrderService;
import com.imageflowpro.image_flow_pro.service.IOrderCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
public class OrderController {

    @Autowired
    private IMediaOrderService iMediaOrderService;
    @Autowired
    private IOrderCommentService iOrderCommentService;

    @GetMapping("/getOrderList")
    public Result<AdminGetOrderListDTO> userGetOrderList(){
        return Result.success(iMediaOrderService.adminGetOrderList());
    }

    @PutMapping("/updateOrder/{orderId}/{nowStatus}")
    public Result adminUpdateOrderStatus(@PathVariable("orderId") Long orderId,@PathVariable Integer nowStatus){
        iMediaOrderService.adminUpdateOrderStatus(orderId,nowStatus);
        return Result.success();
    }

    @PutMapping("/saveOrUpdateComment")
    public Result<OrderComment> saveOrUpdateComment(@RequestBody OrderComment orderComment){
        return Result.success(iOrderCommentService.adminSaveOrUpdateComment(orderComment));
    }

    @DeleteMapping("/deleteComment/{commentId}")
    public Result deleteComment(@PathVariable("commentId")Long commentId){
        iOrderCommentService.adminDeleteComment(commentId);
        return Result.success();
    }

    @PutMapping("/updateOrderIsValid/{orderId}")
    public Result updateOrderIsValid(@PathVariable("orderId") Long orderId){
        iMediaOrderService.adminUpdateOrderIsValid(orderId);
        return Result.success();
    }

    @DeleteMapping("/deleteOrder/{orderId}")//删除为逻辑删除，只删除图片
    public Result deleteOrderById(@PathVariable("orderId") Long orderId){
        iMediaOrderService.deleteOrderById(orderId);
        return Result.success();
    }
}
